//
//  MainBoard.m
//  EFDemo
//
//  Created by mac on 15/3/17.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "MainBoard.h"


@interface MainBoard ()

@end

@implementation MainBoard{
    NSMutableArray *boards;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    [self.customNavLeftBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [self.customNavLeftBtn setFrame:CGRectMakeBound(32, 32)];
    
    self.title = @"EFExtend";
    
    boards = [[NSMutableArray alloc]init];
    
    [boards addObject:@{@"title":@"UI相关",@"subtitle":@"控件、页面",@"map":@"UI"}];
    [boards addObject:@{@"title":@"网络相关",@"subtitle":@"下载、接口、图片",@"map":@"NetWork"}];
    [boards addObject:@{@"title":@"数据相关",@"subtitle":@"数据库、数据解析、转换",@"map":@"DataBase"}];
    [boards addObject:@{@"title":@"其他",@"subtitle":@"动画、第三方、设备",@"map":@"Others"}];
   [self.tableView reloadData];
    
}
- (void)dealloc
{
   
    HM_SUPER_DEALLOC();
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

ON_Button(signal){
    UIButten *btn = signal.source;
    if ([signal is:[UIButten TOUCH_UP_INSIDE]]) {
        if ([btn is:@"leftBtn"]) {
            [self backWithAnimate:YES];
        }
    }
}

#pragma  mark - table delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return boards.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier=@"listCell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (!cell) {
        cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        
    }
    NSDictionary *city = [boards objectAtIndex:indexPath.row];
    cell.textLabel.text = [city valueForKey:@"title"];
    cell.detailTextLabel.text = [city valueForKey:@"subtitle"];
    cell.detailTextLabel.textColor = RGB(.5, .5, .5);
    if (indexPath.row==0) {
        [cell.contentView setBadgeType:1 color:[UIColor redColor] maxSize:CGSizeMake(40, 25)].autoPosition = badgeAutoPosition_Center;
        cell.contentView.badgeText = @"new";
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSDictionary *city = [boards objectAtIndex:indexPath.row];
    NSString *map = [city valueForKey:@"map"];
    NSArray *arr = [map componentsSeparatedByString:@"."];
    if (map.length==0) {

        return;
    }
    if (arr.count==2) {
        map = URLFOR_storyboardWithNav(map);
    }else{
        map = URLFOR_controllerWithNav(map);
    }
    
    HMURLMAPItem* item = [HMURLMap map:map bindto:@"*" URL:map];
    //    item.fullScreen = YES;
    //    item.option = UIViewAnimationOptionTransitionFlipFromLeft;
    //    item.option = UIViewAnimationOptionTransitionCrossDissolve;
    item.option =  UIViewAnimationOptionCurveEaseOut;
    //    item.option = UIViewAnimationOptionTransitionFromLeft;
    //    item.option = UIViewAnimationOptionTransitionFromBottom;
    //    item.option = UIViewAnimationOptionTransitionFromRight;
    UIViewController *vc = [self open:map animate:YES];
    if ([vc isKindOfClass:[UINavigationController class]]) {
        ((UIViewController *)[[(UINavigationController*)vc viewControllers] firstObject]).title = [city valueForKey:@"title"];
    }else{
        vc.title = [city valueForKey:@"title"];
    }
    
}
@end
